package com.liu.domain.base;

import java.io.Serializable;
import java.util.List;

/**
 * 返回分页信息
 *
 * @author LIU
 */
public class PageResult<T> extends BaseResult implements Serializable {
    /**
     * 记录数
     */
    private long total;

    /**
     * 对象集合
     */
    private List<T> data;

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public PageResult() {

    }

    private PageResult(boolean success, String msg) {
        this.setSuccess(success);
        this.setMsg(msg);
    }

    private PageResult(boolean success, List<T> data, long total) {
        this.setSuccess(success);
        this.data = data;
        this.total = total;
    }

    public static PageResult error(String msg) {
        return new PageResult(false, msg);
    }

    public static <T> PageResult<T> success(List<T> data, long total) {
        return new PageResult(true, data, total);
    }

    public static Builder builder(){
        return new Builder();
    }

    public static class Builder {

        public PageResult build() {
            return new PageResult();
        }

        public <T> PageResult<T> of(long rows, List<T> list) {
            return new PageResult(Boolean.TRUE, list, rows);
        }

    }
}
